package xw.qxypt.modules.baseinfo.controller;

import java.util.Arrays;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import org.apache.commons.lang.StringUtils;
import xw.qxypt.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import xw.qxypt.modules.baseinfo.entity.LhpThresholdSettingEntity;
import xw.qxypt.modules.baseinfo.service.LhpThresholdSettingService;
import xw.qxypt.common.utils.PageUtils;
import xw.qxypt.common.utils.R;

import javax.servlet.http.HttpServletRequest;


/**
 * 
 *
 * @author xw
 * @email 
 * @date 2019-11-28 16:38:08
 */
@RestController
@RequestMapping("baseinfo/lhpthresholdsetting")
public class LhpThresholdSettingController {
    @Autowired
    private LhpThresholdSettingService lhpThresholdSettingService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("baseinfo:lhpthresholdsetting:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = lhpThresholdSettingService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("baseinfo:lhpthresholdsetting:info")
    public R info(@PathVariable("id") String id){
        LhpThresholdSettingEntity lhpThresholdSetting = lhpThresholdSettingService.getById(id);

        return R.ok().put("lhpThresholdSetting", lhpThresholdSetting);
    }
    /**
     * 信息
     */
    @RequestMapping("/getInfo/{id}")
    public R getInfo(@PathVariable("id") String id){
        LhpThresholdSettingEntity lhpThresholdSetting = lhpThresholdSettingService.getInfo(id);
        return R.ok().put("lhpThresholdSetting", lhpThresholdSetting);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("baseinfo:lhpthresholdsetting:save")
    public R save(HttpServletRequest request) {
        String data = request.getParameter("data");
        data = data.replaceAll("gt",">").replaceAll("&amp;","&").replaceAll("lt","<");
        LhpThresholdSettingEntity lhpThresholdSetting = JSON.parseObject(data, LhpThresholdSettingEntity.class);
        lhpThresholdSettingService.save(lhpThresholdSetting);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("baseinfo:lhpthresholdsetting:update")
    public R update(HttpServletRequest request){
        String data = request.getParameter("data");
        data = data.replaceAll("gt",">").replaceAll("&amp;","&").replaceAll("lt","<");
        LhpThresholdSettingEntity lhpThresholdSetting = JSON.parseObject(data, LhpThresholdSettingEntity.class);
        lhpThresholdSettingService.updateById(lhpThresholdSetting);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("baseinfo:lhpthresholdsetting:delete")
    public R delete(@RequestBody String[] ids){
        lhpThresholdSettingService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
